//
//  XLFormSectionDescriptor.h
//  XLForm ( https://github.com/xmartlabs/XLForm )
//
//  Copyright (c) 2015 Xmartlabs ( http://xmartlabs.com )
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#import "XLFormRowDescriptor.h"
#import <Foundation/Foundation.h>

typedef NS_OPTIONS(NSUInteger, XLFormSectionOptions) {
    XLFormSectionOptionNone        = 0,
    XLFormSectionOptionCanInsert   = 1 << 0,
    XLFormSectionOptionCanDelete   = 1 << 1,
    XLFormSectionOptionCanReorder  = 1 << 2
};

typedef NS_ENUM(NSUInteger, XLFormSectionInsertMode) {
    XLFormSectionInsertModeLastRow = 0,
    XLFormSectionInsertModeButton = 2
};

@class XLFormDescriptor;
@class XLFormBaseHeaderFooterView;

@interface XLFormSectionDescriptor : NSObject
/** section index,默认0 */
@property (assign, nonatomic) NSInteger section;
/** section tag,默认nil */
@property (nonatomic, strong) NSString * _Nullable tag;
/** header view class 名称;如果设置了headerType，就不需要设置了 */
@property (strong, nonatomic, nullable) NSString *headerClass;
/** section type，通过 XLFormViewController.cellClassesForRowDescriptorTypes 注册;如果设置了headerClass，就不需要设置了 */
@property (strong, nonatomic, nullable) NSString *headerType;
/** 头部view 高度，默认 10 */
@property (assign, nonatomic) CGFloat headerHeight;
/** 底部view 高度，默认 CGFLOAT_MIN */
@property (assign, nonatomic) CGFloat footerHeight;
/** 初始数据，一般是供用户选择、操作的数据源 */
@property (strong, nonatomic, nullable) id textData;
/** 结果值，一般是用户输入、选择、填写的内容 */
@property (strong, nonatomic, nullable) id value;
/** header block */
@property (copy, nonatomic, nonnull) void(^headerClickBlock)(XLFormSectionDescriptor * _Nullable descriptor);
/** 是否收起，默认NO，全部展开 */
@property (assign, nonatomic) BOOL collapse;
/** section 是否需要上传到 server，默认NO，比如普通的审批表格第一个section、审批人section、抄送人section;反之如果用section替换了row的显示，则需要上传到server */
@property (assign, nonatomic) BOOL needUpload;
/** section的rows 是否需要上传到 server，默认YES，目前审批人section、抄送人section不需要上传，因为已经单独准备数据上传了 */
@property (assign, nonatomic) BOOL needUploadRows;
/** header tag */
@property (strong, nonatomic, nullable) NSString * headerTag;

@property (strong, nonatomic, nullable) NSString * title;
@property (strong, nonatomic, nullable) NSString * footerTitle;
@property (strong, nonatomic, readonly, nonnull) NSMutableArray * formRows;

@property (readonly) XLFormSectionInsertMode sectionInsertMode;
@property (readonly) XLFormSectionOptions sectionOptions;
@property (nullable) XLFormRowDescriptor * multivaluedRowTemplate;
@property (readonly, nullable) XLFormRowDescriptor * multivaluedAddButton;
@property (nonatomic, nullable) NSString * multivaluedTag;

@property (weak, null_unspecified) XLFormDescriptor * formDescriptor;
@property (nonnull) id hidden;

#pragma mark - system
+(nonnull instancetype)formSection;
+(nonnull instancetype)formSectionWithTitle:(nullable NSString *)title;
+(nonnull instancetype)formSectionWithTitle:(nullable NSString *)title multivaluedSection:(BOOL)multivaluedSection DEPRECATED_ATTRIBUTE DEPRECATED_MSG_ATTRIBUTE("Use formSectionWithTitle:sectionType: instead");
+(nonnull instancetype)formSectionWithTitle:(nullable NSString *)title sectionOptions:(XLFormSectionOptions)sectionOptions;
+(nonnull instancetype)formSectionWithTitle:(nullable NSString *)title sectionOptions:(XLFormSectionOptions)sectionOptions sectionInsertMode:(XLFormSectionInsertMode)sectionInsertMode;

#pragma mark - public

/**
 是否隐藏

 @return return value description
 */
-(BOOL)isHidden;

/**
 创建section header ,footer view

 @param formController formController description
 @param tableView tableView description
 @return return value description
 */
-(XLFormBaseHeaderFooterView *__nullable)sectionForFormController:(XLFormViewController *__nullable)formController withTableView:(UITableView *__nullable)tableView;

-(BOOL)isMultivaluedSection;

#pragma mark - section 操作
-(void)addFormRow:(nonnull XLFormRowDescriptor *)formRow;
-(void)addFormRow:(nonnull XLFormRowDescriptor *)formRow afterRow:(nonnull XLFormRowDescriptor *)afterRow;
-(void)addFormRow:(nonnull XLFormRowDescriptor *)formRow beforeRow:(nonnull XLFormRowDescriptor *)beforeRow;
-(void)removeFormRowAtIndex:(NSUInteger)index;
-(void)removeFormRow:(nonnull XLFormRowDescriptor *)formRow;
-(void)moveRowAtIndexPath:(nonnull NSIndexPath *)sourceIndex toIndexPath:(nonnull NSIndexPath *)destinationIndex;

#pragma mark - custom

/// 自定义添加按钮样式
/// @param button XLFormRowDescriptor
- (void)customMultivaluedAddButton:(nonnull XLFormRowDescriptor *)button;

@end
